<?php

namespace Admin\Controller;

use Think\Upload;
//网站配置信息
class SiteController extends BaseController {
    
    
    
    public function edt(){
       
            $Site = M('Config');
            $Sit =$Site->find();
            $this->assign('Site',$Sit);
            
            if(IS_POST){
                $data = array(
                    'id'=>$Sit['id'],
                    'name' => I('name'),
                    'scopyright' => I('scopyright'),
                    'seo_title' => I('seo_title'),
                    'seo_keywords' => I('seo_keywords'),
                    'seo_description' => I('seo_description'),
                    'createtime'=>time(),
                );
                if ($_FILES['logo']['tmp_name']!=""){
                    $logo_id = $Site->max('id');
                    $logo=$Site->field('logo')->find($logo_id);
                    unlink($logo['logo']);
                    $upload =new Upload();
                    $upload->maxSize = 3145728;
                    $upload->exts =array('jpg', 'gif', 'png', 'jpeg');
                    $upload->rootPath  =  C('UPLOAD_PATH');
                    $upload->savePath = 'Logo/';
                    $upload->saveName =  'logo_'.intval($logo_id);                  
                    $info =$upload->upload();
                    if (!$info){
                        $this->error($upload->getError());
                    }else {
                        $data['logo']=C('UPLOAD_PATH').$info['logo']['savepath'].$info['logo']['savename'];
                    }
                }
                if ($Site->create($data)){
                    if ($Site->save()){
                        $this->success('修改成功');
                    }else {
                        $this->error('修改失败！');
                    }
                }else {
                    $this->error($Site->getError());
                }
                return ;
            }
 
            $this->display();

        
    } 
    
    

    


    
}